package top.ddandang.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.ddandang.blog.model.pojo.Journal;
import top.ddandang.blog.mapper.JournalMapper;
import top.ddandang.blog.service.JournalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author D
 * @since 2020-07-07
 */
@Service
public class JournalServiceImpl extends ServiceImpl<JournalMapper, Journal> implements JournalService {


    @Resource
    private JournalMapper journalMapper;

    @Async
    @Override
    public void insertJournal(String name, String value, int state) {

        Journal journal = new Journal()
                .setState(state)
                .setOperation(value+name);
        while (true) {
            if(journalMapper.insert(journal) == 1) {
                break;
            }
        }
    }

    @Override
    public List<Journal> listJournal() {
        return journalMapper.selectList(new QueryWrapper<Journal>()
        .orderByDesc("gmt_create"));
    }
}
